package com.ruoyi.voucher.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.voucher.domain.Scrip;
import com.ruoyi.voucher.dto.ScripDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.service.IscripService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证主Controller
 * 
 * @author 孙帆科
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/scrip")
public class scripController extends BaseController
{
    @Autowired
    private IscripService scripService;

    /**
     * 查询凭证主列表
     */
    @RequiresPermissions("voucher:scrip:list")
    @GetMapping("/list")
    public TableDataInfo list(Scrip scrip)
    {
        startPage();
        List<Scrip> list = scripService.selectscripList(scrip);
        return getDataTable(list);
    }

    /**
     * 导出凭证主列表
     */
    @RequiresPermissions("voucher:scrip:export")
    @Log(title = "凭证主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Scrip scrip)
    {
        List<Scrip> list = scripService.selectscripList(scrip);
        ExcelUtil<Scrip> util = new ExcelUtil<Scrip>(Scrip.class);
        util.exportExcel(response, list, "凭证主数据");
    }

    /**
     * 获取凭证主详细信息
     */
    @RequiresPermissions("voucher:scrip:query")
    @GetMapping(value = "/{voucherId}")
    public AjaxResult getInfo(@PathVariable("voucherId") Long voucherId)
    {
        return success(scripService.selectscripByVoucherId(voucherId));
    }

        /**
         * 新增凭证主
         */
        @RequiresPermissions("voucher:scrip:add")
        @Log(title = "凭证主", businessType = BusinessType.INSERT)
        @PostMapping
        public AjaxResult add(@RequestBody Scrip scrip)
        {
            return toAjax(scripService.insertscrip(scrip));
        }

    @PostMapping("/addScripDto")
    public AjaxResult addScripDTO(@RequestBody ScripDTO scripDTO)
    {
        return toAjax(scripService.insertscripDTO(scripDTO));
    }
        /**
         * 修改凭证主
         */
        @RequiresPermissions("voucher:scrip:edit")
        @Log(title = "凭证主", businessType = BusinessType.UPDATE)
        @PutMapping
        public AjaxResult edit(@RequestBody Scrip scrip)
        {
        return toAjax(scripService.updatescrip(scrip));
    }

    /**
     * 删除凭证主
     */
    @RequiresPermissions("voucher:scrip:remove")
    @Log(title = "凭证主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{voucherIds}")
    public AjaxResult remove(@PathVariable Long[] voucherIds)
    {
        return toAjax(scripService.deletescripByVoucherIds(voucherIds));
    }
}
